package handler

import (
	"gin-app/utils/jwt"
	"gin-app/utils/response"
	"github.com/gin-gonic/gin"
	"net/http"
)

func Ping(c *gin.Context) {
	response.Success(c, "pong")
}

func SecureDate(c *gin.Context) {
	response.Success(c, gin.H{"data": "secure content"})
}

func Login(c *gin.Context) {
	var loginData struct {
		Username string `json:"username"`
		Password string `json:"password"`
	}
	if err := c.ShouldBind(&loginData); err != nil {
		response.Fail(c, http.StatusBadRequest, "Invalid input")
		return
	}
	if loginData.Username == "admin" && loginData.Password == "123456" {
		token, error := jwt.GenerateToken(loginData.Username)
		if error != nil {
			response.Fail(c, http.StatusInternalServerError, "Token generation failed")
			return
		}
		response.Success(c, gin.H{"token": token, "username": loginData.Username})
	}
}
